import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Ground here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Ground extends Actor
{
    int index;
    int terrainNum;
    
    /**
     * Creates a new Ground which the player can stand on. Receives the index.
     */
    public Ground(int num)
    {
        index=num;
        terrainNum=1;
        //loadImages();
        //setSkin();
    }
    
    /*public void loadImages()
    {
        for(int i=0;i<=10;i++)
        {
            images[i]=new GreenfootImage("ground_jungle"+i+".png");
        }
    }*/
            
    public void act() 
    {
        setSkin();
        
        GameWorld world=(GameWorld)getWorld();
        int scrollx=world.getScrollx();
        int width=world.getWidth();
        int num=world.getTerrainNum();
        
        setLocation(scrollx+width*index,world.getHeight()/2);
        
        if(terrainNum<num)
        {
            index--;
            terrainNum=num;
        }else
        
        if(terrainNum>num)
        {
            index++;
            terrainNum=num;
        }
    }
    
    public void setSkin()
    {
        setImage(((GameWorld)getWorld()).getImage(1,index));
    }
}
